package com.jwgf.smarowindingmachine_unity.ui;


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.jwgf.common.ViewCache;
import com.jwgf.smarowindingmachine_unity.R;

public class ProductionManagementVarietyManagementFragment extends BaseFragment{
	public static final String TAG = "ProductionManagementVarietyManagement";

	private EditText variety;
	private EditText employee;
	private EditText batch;
	
	private String DEFAULT_VALUE = "0";
	private SharedPreferences classPreference;
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
//		variety = (EditText) getActivity().findViewById(R.id.pm_variety_management_variety_edit);
//		variety.setBackgroundDrawable(null);
//		variety.setOnEditorActionListener(this);
//		variety.setSelectAllOnFocus(true);
//		batch = (EditText) getActivity().findViewById(R.id.pm_variety_management_batch_edit);
//		batch.setBackgroundDrawable(null);
//		batch.setOnEditorActionListener(this);
//		batch.setSelectAllOnFocus(true);
//		employee = (EditText) getActivity().findViewById(R.id.pm_variety_management_employee_edit);
//		employee.setBackgroundDrawable(null);
//		employee.setOnEditorActionListener(this);
//		employee.setSelectAllOnFocus(true);
//		classPreference = getActivity().getSharedPreferences(MachineParameterSharedPreference.getInstance().CLASSES_PREF, Context.MODE_PRIVATE);
		
		initialParams();
	}

	private void initialParams() {
//		String v = classPreference.getString(MachineParameterSharedPreference.getInstance().PRODUCTION_VARIETY, DEFAULT_VALUE);
//		variety.setText(v);
//		String b = classPreference.getString(MachineParameterSharedPreference.getInstance().PRODUCTION_BATCH, DEFAULT_VALUE);
//		batch.setText(b);
//		String e = classPreference.getString(MachineParameterSharedPreference.getInstance().PRODUCTION_EMPLOEE, DEFAULT_VALUE);
//		employee.setText(e);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = ViewCache.getInstance().getView(R.layout.fragment_production_management_variety_management);
		
		return v;
	}
	
	
	@Override
	public void onDestroy() {
		super.onDestroy();
		hideKeyboard(variety);
	}

	private void hideKeyboard(View v) {
		InputMethodManager imm = (InputMethodManager) getActivity()
				.getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
	}

//	public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
//
//		if (actionId == EditorInfo.IME_ACTION_DONE
//				|| (event != null && event.getAction() == KeyEvent.ACTION_DOWN)) {
//			int id = v.getId();
//			String value = ((v.getText().length() == 0) ? DEFAULT_VALUE:  v.getText().toString());
//			switch (id) {
//			case R.id.pm_variety_management_variety_edit: {
//				classPreference
//						.edit()
//						.putString(MachineParameterSharedPreference.getInstance().PRODUCTION_VARIETY, value)
//						.commit();
//				break;
//			}
//			case R.id.pm_variety_management_batch_edit: {
//				classPreference
//						.edit()
//						.putString(MachineParameterSharedPreference.getInstance().PRODUCTION_BATCH, value)
//						.commit();
//				break;
//			}
//			case R.id.pm_variety_management_employee_edit: {
//				classPreference
//						.edit()
//						.putString(MachineParameterSharedPreference.getInstance().PRODUCTION_EMPLOEE, value)
//						.commit();
//				break;
//			}
//			default:
//				break;
//			}
//		}
//		return false;
//	
//	}
}
